from typing import List, Optional, Union
from datetime import datetime
from pydantic import Field

from server.schemas.BaseSchema import BaseSchema

class UserBase(BaseSchema):
    """基础类"""
    username: str = Field(..., min_length=3, max_length=100)
    # 可选参数
    phone: str = Field(None, min_length=11, max_length=11)
    real_name: str = Field(None, min_length=3, max_length=100)
    is_active: bool = True


class UserCreate(UserBase):
    """创建用户"""
    password: str = Field(...)
    is_superuser: bool = False


class UserUpdate(BaseSchema):
    """
    修改用户信息
    """
    id: str = Field(..., min_length=18)
    username: str = Field(None, min_length=3, max_length=100)
    phone: str = Field(None, min_length=11, max_length=11)
    real_name: str = Field(None, min_length=3, max_length=100)
    is_active: bool = True
    is_superuser: bool = False


class UserDelete(BaseSchema):
    """删除用户"""
    id: Union[str, List[str]] = Field(..., min_length=18)


class UserPasswordReset(BaseSchema):
    """重置密码"""
    id: str = Field(..., min_length=18)


class UserAlreadyExists(BaseSchema):
    code: int = 1400
    msg: str = '用户已存在'


class UserResponse(BaseSchema):
    """数据库用户Schema"""
    id: str
    username: str
    phone: str
    real_name: str
    is_superuser: bool
    is_active: bool
    created_at: datetime
    updated_at: datetime
    avatar: Optional[str] = None

class UserQueryResponse(BaseSchema):
    data: UserResponse
    code: int = 200
    msg: str = '操作成功'


class UserListResponse(BaseSchema):
    data: List[UserResponse]
    code: int = 200
    msg: str = '操作成功'




class PasswordValidateError(BaseSchema):
    code: int = 1402
    msg: str = "密码长度大于8且必须为数值、大小写字母、特殊字符组合"

